﻿//-------------------------------------------------------------------------------------------
// <copyright file="TransactionsViewModel.cs" company="Russell Wilkins">
//     Copyright (c) Russell Wilkins 2014. All Rights Reserved.
// </copyright>
// <author>Russell Wilkins</author>
// <license href="license.txt">
//     The use of this software is governed by the Microsoft Public License
//     which is included with this distribution.
// </license>
//-------------------------------------------------------------------------------------------
namespace Ripple.TestClient.ViewModels
{
    using Ripple.Data;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// TODO: Describe the class
    /// </summary>
    public class TransactionsViewModel : ListViewModel<Account, TransactionViewModel>
    {
        /// <summary>
        /// Initializes a new instance of the TransactionsViewModel class.
        /// </summary>
        public TransactionsViewModel(IRippleContext rippleContext, Account account)
        {
            this.RippleContext = rippleContext;
            this.Model = account;
        }

        private IRippleContext RippleContext { get; set; }

        protected override void RefreshList()
        {
            string modelId = this.Model.Id;

            Task.Factory.StartNew(new Action(() =>
                {
                    foreach (Transaction item in this.RippleContext.Transactions.GetForAccount(modelId))
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            TransactionViewModel vm = new TransactionViewModel(item);
                            vm.Model = item;
                            ListItems.Add(vm);
                        }));
                    }
                }
            ));
        }
    }
}